package com.gok.einvoice.web.service.impl;

import com.gok.einvoice.common.exception.base.BaseException;
import com.gok.einvoice.common.utils.DateUtils;
import com.gok.einvoice.common.utils.SecurityUtils;
import com.gok.einvoice.common.utils.StringUtils;
import com.gok.einvoice.web.entity.TaxiInvoice;
import com.gok.einvoice.web.mapper.TaxiInvoiceMapper;
import com.gok.einvoice.web.service.ITaxiInvoiceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 出租车发票Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-24
 */
@Service
public class TaxiInvoiceServiceImpl implements ITaxiInvoiceService
{
    @Resource
    private TaxiInvoiceMapper taxiInvoiceMapper;

    /**
     * 查询出租车发票
     *
     * @param id 出租车发票主键
     * @return 出租车发票
     */
    @Override
    public TaxiInvoice selectTaxiInvoiceById(Integer id)
    {
        return taxiInvoiceMapper.selectTaxiInvoiceById(id);
    }

    /**
     * 查询出租车发票列表
     *
     * @param taxiInvoice 出租车发票
     * @return 出租车发票
     */
    @Override
    public List<TaxiInvoice> selectTaxiInvoiceList(TaxiInvoice taxiInvoice)
    {
        return taxiInvoiceMapper.selectTaxiInvoiceList(taxiInvoice);
    }

    /**
     * 新增出租车发票
     *
     * @param taxiInvoice 出租车发票
     * @return 结果
     */
    @Override
    public int insertTaxiInvoice(TaxiInvoice taxiInvoice)
    {
        taxiInvoice.setCreateTime(DateUtils.getNowDate());
        String createId = SecurityUtils.getUserId().toString();
        if (!StringUtils.isEmpty(createId)) {
            taxiInvoice.setCreateBy(createId);
        }
        //判断是否重复上传
        List<TaxiInvoice> taxiInvoices = taxiInvoiceMapper.selectTaxiInvoiceList(taxiInvoice);
        if (taxiInvoices.size() > 0) {
            throw new BaseException("已上传过该发票");
        }
        return taxiInvoiceMapper.insertTaxiInvoice(taxiInvoice);
    }

    /**
     * 修改出租车发票
     *
     * @param taxiInvoice 出租车发票
     * @return 结果
     */
    @Override
    public int updateTaxiInvoice(TaxiInvoice taxiInvoice)
    {
        taxiInvoice.setUpdateTime(DateUtils.getNowDate());
        return taxiInvoiceMapper.updateTaxiInvoice(taxiInvoice);
    }

    /**
     * 批量删除出租车发票
     *
     * @param ids 需要删除的出租车发票主键
     * @return 结果
     */
    @Override
    public int deleteTaxiInvoiceByIds(Integer[] ids)
    {
        return taxiInvoiceMapper.deleteTaxiInvoiceByIds(ids);
    }

    /**
     * 删除出租车发票信息
     *
     * @param id 出租车发票主键
     * @return 结果
     */
    @Override
    public int deleteTaxiInvoiceById(Integer id)
    {
        return taxiInvoiceMapper.deleteTaxiInvoiceById(id);
    }
}
